<?php
// 收藏商品
require_once $this->website['path']['action'] . '/app/token.php';

$json = array('status' => 'error', 'msg' => '', 'data' => '');
$sys = fn_configura($this->website, "sys");

$pid = fn_post('pid');

if ($this->website['class']['db']
	->table("product_collect")
	->where('uid=? and pid=?', $basic['uid'], $pid)
	->limit(1)
	->count()) {
	$json['msg'] = '已收藏过';
} elseif ($this->website['class']['db']
		->table("product_collect")
		->where('uid=?', $basic['uid'])
		->count() >= $sys['productcollect']) {
	$json['msg'] = '收藏数量已达到' . $sys['productcollect'] . '上限';
} elseif (!$this->website['class']['db']
		->table('product')
		->where('id=?', $pid)
		->limit(1)
		->count()) {
	$json['msg'] = '商品不存在或已被删除';
} else {
	$cid = $this->website['class']['db']
		->table("product_collect")
		->field('uid', 'pid', 'createtime')
		->value($basic['uid'], $pid, $_SERVER['REQUEST_TIME'])
		->insert();
	if (!$cid) {
		$json['msg'] = '保存失败,请稍后再试';
	} else {
		$json['status'] = 'ok';
		$json['msg'] = '收藏成功';
	}
}
// $json['sql'] = $this->website['class']['db']->sql;
$json['basic'] = $basic;
$this->json_encode_encrypt($json);
